<template>
  <div class="scenicinfo box">
    <div class="backbox">
      <img
        src="@/assets/img/back.png"
        class="goback"
        @click="$router.replace('/sceniclist')"
      />
    </div>
    <div class="scenicinfocontainer">
      <div class="dkbtn" v-if="signDetail.status == 0" @click="toUpload">
        <img src="@/assets/img/dkbtn.png" />
      </div>
      <div class="dkbtn" v-else @click="toCheck">
        <img src="@/assets/img/dk_jindu_btn.png" />
      </div>
      <div class="infotopbox clmstart">
        <img :src="scenicInfo.poster_url" class="headimg" />
        <div class="sceniccont">
          <div class="namebox">
            <div class="ttitle">名称：</div>
            <div class="tcont">{{ scenicInfo.name }}</div>
          </div>
          <div class="didianbox">
            <div class="ttitle">地点：</div>
            <div class="tcont">
              {{ scenicInfo.address }}
              <img
                src="@/assets/img/mapto.png"
                @click="
                  mapTo(
                    scenicInfo.latitude,
                    scenicInfo.longitude,
                    scenicInfo.name
                  )
                "
              />
            </div>
          </div>
        </div>
      </div>
      <!-- 推荐 -->
      <div class="tjlistcontainer clmstart">
        <!-- 基本情况 -->
        <div class="tjitem jbbox">
          <div class="title">
            <img src="@/assets/img/tj-jb.png" />
          </div>
          <div class="tjinfobox clmstart">
            <div class="tjimgbox clmstart">
              <div class="cardhead"></div>
              <!-- <div v-swiper:bySwiper="bySwiperOption">
                <div class="swiper-wrapper">
                  <div
                    class="swiper-slide"
                    v-for="bitem in scenicInfo.care_recommend_url"
                    :key="bitem"
                  >
                    <img :src="bitem" />
                  </div>
                </div>
              </div> -->
              <div class="imgbox">
                <img :src="scenicInfo.base_detail_url" />
              </div>
            </div>
            <div class="tjtext">
              <p>{{ scenicInfo.base_detail_content }}</p>
            </div>
          </div>
          <img src="@/assets/img/radius.png" class="boxradius" />
        </div>
        <!-- 骑遇攻略 -->
        <div class="tjitem qybox">
          <div class="title">
            <img src="@/assets/img/tj-qy.png" />
          </div>
          <div class="tjinfobox clmstart">
            <div class="tjtext">
              <p>{{ scenicInfo.intro_content }}</p>
            </div>
          </div>
          <img src="@/assets/img/radius.png" class="boxradius" />
        </div>
      </div>
    </div>
    <!-- 邮寄-填写收货地址 -->
    <Online
      :jpname="signDetail.prize"
      :jpimg="require(`@/assets/img/jp/g${signDetail.prizeId}.png`)"
      :wid="signDetail.wid"
      @closeOnline="OnlineSubCallBack"
      v-if="online_no_write_flag"
    />
    <!-- 邮寄-已填写,话费 -->
    <Gift
      :jpname="signDetail.prize"
      :jpimg="require(`@/assets/img/jp/g${signDetail.prizeId}.png`)"
      :tipflag="tipflag"
      v-if="online_is_write_flag"
    />
    <!-- 门店领取-需要填写摩托车编号 -->
    <Underline
      :jpname="signDetail.prize"
      :jpimg="require(`@/assets/img/jp/g${signDetail.prizeId}.png`)"
      :wid="signDetail.wid"
      @subCall="underlineSubCallBack"
      v-if="underline_no_write_flag"
    />
    <!-- 门店领取-不需要填写摩托车编号 -->
    <HxQrcode :qrcode="signDetail.qrcode" v-if="underline_is_write_flag" />
    <!-- 积分 -->
    <Jifen :jpname="signDetail.prize + ''" v-if="jifenflag" />
  </div>
</template>
<script>
import Online from "@/components/Online.vue";
import Gift from "@/components/Gift.vue";
import Underline from "@/components/Underline.vue";
import HxQrcode from "@/components/HxQrcode.vue";
import Jifen from "@/components/Jifen.vue";
import { Toast } from "vant";
import wx from "weixin-js-sdk";
export default {
  data() {
    return {
      scenicInfo: {
        // id: "2",
        // city: "北京",
        // name: "摩遇机车俱乐部2",
        // address: "重庆市南岸区南滨路珊瑚水岸21-22号3",
        // poster_url:
        //   "http://dove-2021.oss-cn-shanghai.aliyuncs.com/20230425185342957585.png",
        // base_detail_url:
        //   "http://dove-2021.oss-cn-shanghai.aliyuncs.com/20230419103730965289.jpeg",
        // base_detail_content:
        //   "摩遇机车俱乐部擅长国产中大排及进口大贸车辆的维修、保养及改装业务",
        // intro_content:
        //   "摩遇机车俱乐部擅长国产中大排及进口大贸车辆的维修、保养及改装业务",
      },
      distance: 0, //打卡距离
      signDetail: {
        // status: "", // 打卡状态 0代表未打卡，2代表已打卡
        // exch_method: 1, // 1代表邮寄产品，2代表门店领取，3代表积分，4代表话费
        // wid: 1, // 中奖记录id
        // prize: "", // 奖品名称
        // prizeId: "", // 奖品ID
        // isNeedWriteMotorCode: "", // exch_method为2 是否需要填写摩托车编号 1:需要填 0：不需要填
        // qrcode: "", // 核销二维码 isNeedWriteMotorCode为0时
        // isNeedWriteReceiver: 1, // exch_method为1 1：需要填 0：不需要填
        // receiver: "", // 收件人
        // mobile: "", // 收件人手机号
        // motor_code: "", // 摩托车编号
        // address: "", // 收件人地址
      },
      online_no_write_flag: false, // 邮寄 未填写地址
      online_is_write_flag: false, // 邮寄 已填写地址,话费
      underline_no_write_flag: false, // 门店领取 需要填写摩托车编号
      underline_is_write_flag: false, // 门店领取 不需要填写摩托车编号
      jifenflag: false, // 积分
      tipflag: false,
    };
  },
  created() {
    let id = this.$route.params.id;
    // console.log(id);
    this.queryScenicInfo(id);
  },
  methods: {
    //查询门店详情
    queryScenicInfo(id) {
      Toast.loading({
        message: "loading...",
        forbidClick: true,
        duration: 0, //值为 0 时，toast 不会消失
        overlay: true, //是否显示背景遮罩层
      });
      this.$http
        .post("/getScenicDetailById", {
          id,
          latitude: window.localStorage.getItem("latitude"),
          longitude: window.localStorage.getItem("longitude"),
        })
        .then((res) => {
          Toast.clear();
          // console.log(res);
          if (res.data.code == 200) {
            this.scenicInfo = res.data.data.info;
            this.signDetail = res.data.data.signDetail;
            this.distance = res.data.data.distance;
          } else {
            Toast(res.data.msg);
          }
        });
    },
    //打开携程
    xiechengTo(url) {
      window.open(url, "_blank");
    },
    //打开地图
    mapTo(latitude, longitude, name) {
      var url = encodeURIComponent(window.location.href.split("#")[0]);
      this.$http
        .post("https://www.mahelei.com/index.php/Gm/Wechat/share", { url })
        .then((res) => {
          let data = res.data;
          wx.config({
            debug: false,
            appId: data.appId,
            timestamp: data.timestamp,
            nonceStr: data.nonceStr,
            signature: data.signature,
            jsApiList: ["checkJsApi", "openLocation"],
            success(res) {
              //   Toast(res);
            },
          });
        });
      wx.ready(() => {
        wx.checkJsApi({
          jsApiList: ["openLocation"],
          success: (rest) => {
            //打开指定位置
            wx.openLocation({
              latitude: latitude, // 纬度，浮点数，范围为90 ~ -90
              longitude: longitude, // 经度，浮点数，范围为180 ~ -180。
              name: name, // 位置名
              address: "", // 地址详情说明
              scale: 18, // 地图缩放级别,整型值,范围从1~28。默认为最大
              infoUrl: "", // 在查看位置界面底部显示的超链接,可点击跳转
            });
          },
        });
      });
    },
    // 去打卡
    toUpload() {
      if (this.distance > 1000) {
        Toast("超出打卡范围！");
        return;
      }
      this.$router.replace({
        name: "upload",
        params: {
          location_id: this.scenicInfo.id,
          latitude: window.localStorage.getItem("latitude"),
          longitude: window.localStorage.getItem("longitude"),
          type: "2",
          name: this.scenicInfo.name,
        },
      });
    },
    // 查看打卡进度
    toCheck() {
      // console.log(this.signDetail);
      // 1代表邮寄产品，2代表门店领取，3代表积分，4代表话费
      if (this.signDetail.exch_method == "1") {
        // 邮寄产品
        if (this.signDetail.isNeedWriteReceiver == "1") {
          // 未填写
          this.online_no_write_flag = true;
        } else {
          // 已填写
          this.tipflag = true;
          this.online_is_write_flag = true;
        }
      } else if (this.signDetail.exch_method == "2") {
        // 门店领取
        if (this.signDetail.isNeedWriteMotorCode == "1") {
          // 未填写摩托车编号
          this.underline_no_write_flag = true;
        } else {
          // 已填写摩托车编号
          this.underline_is_write_flag = true;
        }
      } else if (this.signDetail.exch_method == "3") {
        // 积分
        this.jifenflag = true;
      } else if (this.signDetail.exch_method == "4") {
        // 话费
        this.tipflag = false;
        this.online_is_write_flag = true;
      }
    },
    // 邮寄信息提交成功
    OnlineSubCallBack() {
      this.online_no_write_flag = false;
      let id = this.$route.params.id;
      this.queryScenicInfo(id);
    },
    // 提交成功-线下领取 摩托车编号
    underlineSubCallBack(qrcode) {
      this.underline_no_write_flag = false;
      this.signDetail.qrcode = qrcode;
      this.underline_is_write_flag = true;
    },
  },
  components: {
    Online,
    Gift,
    Underline,
    HxQrcode,
    Jifen,
  },
};
</script>
<style lang="less" scoped>
.scenicinfo {
  overflow-y: scroll;
  .backbox {
    position: absolute;
    z-index: 2;
  }
  .scenicinfocontainer {
    position: relative;
    width: 100%;
    height: auto;
    min-height: 100%;
    background: url("@/assets/img/bg.jpg") repeat-y;
    background-size: cover;
    .dkbtn {
      position: fixed;
      right: 1rem;
      top: 28rem;
      width: 179px;
      height: 179px;
      overflow: hidden;
      z-index: 9;
      img {
        display: block;
        width: 100%;
      }
    }
    .infotopbox {
      position: relative;
      width: 100%;
      height: auto;
      .headimg {
        width: 100%;
        height: 540px;
        object-fit: cover;
        vertical-align: middle;
      }
      .sceniccont {
        width: 100%;
        height: 362px;
        margin-top: -5rem;
        background: url("@/assets/img/infotopbox.png") no-repeat;
        background-size: 100% 100%;
        font-size: 1.8rem;
        div {
          text-align: left;
        }
        .namebox,
        .didianbox {
          width: 93%;
          margin: 0 auto;
          display: flex;
          justify-content: flex-start;
          align-items: flex-start;
          div {
            padding: 0.5rem 0;
          }
          .ttitle {
            width: 100px;
            font-family: "AlibabaPuHuiTi-2-85-Bold";
          }
          .tcont {
            width: calc(100% - 100px);
            a {
              text-decoration: none;
            }
          }
        }
        .namebox {
          padding-top: 5rem;
        }
        .didianbox {
          div {
            img {
              margin: 1rem 0;
            }
          }
        }
      }
    }
    // 推荐列表
    .tjlistcontainer {
      width: 100%;
      padding-bottom: 6rem;
      .tjitem {
        position: relative;
        width: 729px;
        height: auto;
        background: url("@/assets/img/tjbg.png") no-repeat top center;
        background-size: contain;
        margin: 2rem 0 1rem 21px;
        .boxradius {
          position: absolute;
          right: 1.8rem;
          top: 6.6rem;
        }
        .title {
          position: relative;
          width: 50%;
          height: 95px;
          margin-left: 2rem;
          img {
            padding-top: 2rem;
          }
        }
        .tjinfobox {
          width: 97.5%;
          height: auto;
          min-height: 708px;
          background-color: #fbce07;
          border: 2px solid #f39500;
          box-sizing: border-box;
          border-top: none;
          border-radius: 1.5rem;
          .tjtext,
          .tjimgbox {
            width: 92%;
            border-radius: 1rem;
          }
          .tjtext {
            margin-top: 2rem;
            min-height: 240px;
            background: #ffffff;
            margin-bottom: 3rem;
            p {
              font-size: 1.5rem;
              color: #000000;
              padding: 1.5rem;
            }
          }
          .tjimgbox {
            position: relative;
            height: 353px;
            border: 5px solid #000000;
            box-sizing: border-box;
            margin-top: 2.5rem;
            .cardhead {
              position: absolute;
              top: -12px;
              width: 140px;
              height: 12px;
              border-radius: 2rem;
              background: #000000;
            }
            .imgbox {
              width: 100%;
              height: 100%;
              overflow: hidden;
              img {
                display: block;
                width: 100%;
              }
            }
            // .swiper-container {
            //   position: relative;
            //   width: 100%;
            //   height: 100%;
            //   margin: 0;
            //   padding: 0;
            //   border-radius: 1rem;
            //   overflow: hidden;
            //   .swiper-slide {
            //     display: flex;
            //     flex-flow: column nowrap;
            //     justify-content: center;
            //     align-items: center;
            //     font-size: 2rem;
            //     img {
            //       width: 100%;
            //       height: 100%;
            //       object-fit: cover;
            //     }
            //   }
            // }
          }
          .slidetip {
            margin: 1.5rem auto;
          }
        }
      }
    }
  }
}
</style>
